package com.ddwl.message.dao;

import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.constant.Constant;
import com.ddwl.common.dao.TkDao;
import com.ddwl.message.mapper.WebSocketMessageMapper;
import com.ddwl.message.model.WebSocketMessage;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author hemiaojun
 * @Date 2020/12/22 14:16
 */
@Repository
public class WebSocketMessageDao extends TkDao<WebSocketMessageMapper,WebSocketMessage> {

    @Resource
    private WebSocketMessageMapper webSocketMessageMapper;

    public List<WebSocketMessage> getNotSentBySessionId(String sessionId) {
        WebSocketMessage wsMessage = new WebSocketMessage();
        wsMessage.setSessionId(sessionId);
        wsMessage.setStatus(BaseEnum.StatusEnum.DISABLE.getCode());
        return this.select(wsMessage);
    }

    public void updateStatus(List<String> ids, Integer status) {
        Example example = getExample();
        example.and().andIn("id", ids);
        WebSocketMessage wsMessage = new WebSocketMessage();
        wsMessage.setStatus(status);
        webSocketMessageMapper.updateByExampleSelective(wsMessage, example);
    }

    public List<WebSocketMessage> getAll() {
        Example example = new Example(WebSocketMessage.class);
        return webSocketMessageMapper.selectByExample(example);
    }

    public void changeId(Map<String, String> map) {
        webSocketMessageMapper.changeId(map);
    }
}
